﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace QMERP.Infrastructure.EFCore.EFCore
{
    public class LogOperateMapping : IEntityTypeConfiguration<LogOperate>
    {
        public void Configure(EntityTypeBuilder<LogOperate> builder)
        {
            builder.Property(x => x.UserName).HasMaxLength(50);
            builder.Property(x => x.LogOn).HasColumnType("datetime");
            builder.Property(x => x.IP).IsRequired(false).HasMaxLength(200);
            builder.Property(x => x.City).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.UserAgent).IsRequired(false).HasMaxLength(500);
            builder.Property(x => x.Browser).IsRequired(false).HasMaxLength(200);
            builder.Property(x => x.Os).IsRequired(false).HasMaxLength(200);
            builder.Property(x => x.ElapsedMilliseconds);
            builder.Property(x => x.ApiName).HasMaxLength(50);
            builder.Property(x => x.ApiUrl).HasMaxLength(50);
            builder.Property(x => x.ApiMethod).HasMaxLength(50);
            builder.Property(x => x.Request).IsRequired(false);
            builder.Property(x => x.Response).IsRequired(false);
            builder.Property(x => x.IsSuccess);
            builder.Property(x => x.ErrorMessage).IsRequired(false);
            builder.Property(x => x.Exception).IsRequired(false);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.UserName);
            builder.HasIndex(x => x.LogOn);
            builder.HasIndex(x => x.ApiName);
            builder.HasIndex(x => x.ApiUrl);
        }
    }
}
